package com.lantosec.hmrp.modules.monitor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lantosec.hmrp.core.util.MonitorUtils;
import com.lantosec.hmrp.modules.monitor.entity.PatrolDetailsEntity;
import com.lantosec.hmrp.modules.monitor.entity.PatrolEntity;
import com.lantosec.hmrp.modules.monitor.mapper.MonitorPatrolMapper;
import com.lantosec.hmrp.modules.monitor.service.IMonitorPatrolService;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service()
@Primary
@Log4j2
@SuppressWarnings("all")
public class MonitorPatrolServiceImpl extends ServiceImpl<MonitorPatrolMapper, PatrolEntity> implements IMonitorPatrolService {
    @Override
    public List<PatrolEntity> getPatrolList(String month, String year) {
        List<PatrolEntity> param = null;
        String startTime = null;
        String endTime = null;
        if (StringUtils.isNotBlank(month)) {
            String[] monthSplit = month.split("-");
            startTime = MonitorUtils.getFirstDayOfMonth(Integer.valueOf(monthSplit[1]));
            endTime = MonitorUtils.getLastDayOfMonth(Integer.valueOf(monthSplit[1]));
        } else if (StringUtils.isNotBlank(year)) {
            startTime = year;
        } else {
            month = MonitorUtils.getLastMonth();
            startTime = MonitorUtils.lastMonthFirstDay();
            endTime = MonitorUtils.lastMonthLastDay();
        }
        param = baseMapper.getPatrolList(month,year,startTime,endTime);
        return param;
    }

    @Override
    public List<PatrolDetailsEntity> getPatrolListDetail(String month, String year, String deptId) {
        List<PatrolDetailsEntity> param = null;
        String startTime = null;
        String endTime = null;
        if (StringUtils.isNotBlank(month)) {
            String[] monthSplit = month.split("-");
            startTime = MonitorUtils.getFirstDayOfMonth(Integer.valueOf(monthSplit[1]));
            endTime = MonitorUtils.getLastDayOfMonth(Integer.valueOf(monthSplit[1]));
        } else if (StringUtils.isNotBlank(year)) {
            startTime = year;
        } else {
            month = MonitorUtils.getLastMonth();
            startTime = MonitorUtils.lastMonthFirstDay();
            endTime = MonitorUtils.lastMonthLastDay();
        }
        param = baseMapper.getPatrolListDetail(month,year,startTime,endTime,deptId);
        return param;
    }
}
